package com.hxzy.common.util;

import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.hxzy.common.exception.ServiceException;
import com.hxzy.common.util.strategy.CartStorategy;
import com.hxzy.common.util.strategy.RedisCartStrategy;
import com.hxzy.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 购物车工厂
 */
@Component
public class CartFactory {

    /**
     * 购物车实现的算法类型  (database/redis)
     */
    @Value(value = "${cart.storategy:database}")
    private String type;

    /**
     * database实现
     */
    @Autowired
    private ShoppingCartService shoppingCartService;

    @Autowired
    private RedisCartStrategy  redisCartStrategy;

    /**
     * 简单工厂创建算法
     * @return
     */
    public CartStorategy getCartStorategy(){

        if(type.equals("database")){
            return shoppingCartService;
        }else if(type.equals("redis")){
            return redisCartStrategy;
        }

        return null;
    }

}
